<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
      Function.prototype.bind2 = function(context){
          let self = this;
          let args = Array.prototype.slice.call(arguments,1);
          let fNOP = function (){}
          let fBound = function (){
            let bindArgs = Array.prototype.slice.call(arguments);
            return self.apply(this instanceof fBound?this:context,args.concat(bindArgs))
          }
          fNOP.prototype = this.prototype
          fBound.prototype = new fNOP()
          return fBound 
      }
      var value = 500
      var foo = {
          value:200
      }
      function bar(name,age){
          console.log(name)
          console.log(age)
          console.log(value)
      }
        var bindFoo = bar.bind2(foo,"yukeke")
        var obj = new bindFoo(18)
      console.log(obj)

    </script>
</body>
</html>